<template>
  <div
      id="ConsoleMediaServer"
      style="width: 100%; height: 100%; background: #ffffff; text-align: center">
    <div ref="ConsoleMEM" :style="{ width:'100%',height:'100%' }"></div>
  </div>
</template>

<script>
import moment from 'moment/moment'
import * as echarts from "echarts";

export default {
  name: 'ConsoleMediaServer',
  data() {
    return {
      chartData: {
        columns: ['time', 'in', 'out'],
        rows: [],
      },
      chartSettings: {
        area: true,
        labelMap: {
          in: '下载',
          out: '上传',
        },
      },
      option: {
        title: {
          show: true,
          text: '网络',
          left: 'center',
          top: 20,
        },
        grid: {
          show: true,
          right: '30px',
          containLabel: true,
        },
        xAxis: {
          time: 'time',
          max: 'dataMax',
          boundaryGap: ['20%', '20%'],
          axisLabel: {
            formatter: (v) => {
              return moment(v).format('HH:mm:ss')
            },
            showMaxLabel: true,
            interval: 'auto',
            rotate: 45
          },
        },
        tooltip: {
          trigger: 'axis',
          formatter: (data) => {
            console.log(parseFloat(data[0].data[1]).toFixed(2))
            console.log(parseFloat(data[1].data[1]).toFixed(2))
            console.log('############')
            return (
                '下载：' +
                parseFloat(data[0].data[1]).toFixed(2) +
                'Mbps' +
                '</br> 上传：' +
                parseFloat(data[1].data[1]).toFixed(2) +
                'Mbps'
            )
          },
        },
        legend: {
          left: 'center',
          bottom: '15px',
        },
      },
    }
  },
  mounted() {
    this.initChart();
    this.$nextTick((_) => {
      setTimeout(() => {
        this.$refs.ConsoleMEM.echarts.resize()
      }, 100)
    })
  },
  unmounted() {
  },
  methods: {
    setData: function (data) {
      this.option.series[0].data = data;
      this.chart.setOption(this.option);
    },
    initChart() {
      this.chart = markRaw(echarts.init(this.$refs.ConsoleMEM));
    }
  },
}
</script>
